import 'package:changxindianzishangwu/dao/login_init_dao.dart';
import 'package:changxindianzishangwu/model/base_model.dart';
import 'package:changxindianzishangwu/util/app_color.dart';
import 'package:changxindianzishangwu/util/colors.dart';
import 'package:changxindianzishangwu/util/toast.dart';
import 'package:changxindianzishangwu/util/universal_view.dart';
import 'package:changxindianzishangwu/widget/app_bar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

///扫码登录=>确认

class LoginZxingDialog extends StatefulWidget {
  String qrCodeKey;

  LoginZxingDialog(this.qrCodeKey, {Key key}) : super(key: key);

  @override
  _LoginZxingDialogState createState() => _LoginZxingDialogState();
}

class _LoginZxingDialogState extends State<LoginZxingDialog> {
  TextStyle _style(double s, color) {
    return TextStyle(fontSize: sp(s), color: color);
  }

  void _qrLogin() async {
    BaseModel _model = await LoginInitDao.qrLogin(widget.qrCodeKey, 2);
    if (_model.resultCode == 1) {
      toast("登录成功");
      Get.back();
    }else{
      toast("登录失败：${_model.resultMsg}");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TopAppBar(context, "登录确认"),
      body: Container(
        margin: EdgeInsets.all(width(15)),
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(15))),
        child: Column(
          children: [
            SizedBox(
              height: height(90),
            ),
            Image.asset(
              "images/ic_wx_login_web.png",
              width: width(60),
              height: width(50),
            ),
            SizedBox(
              height: height(30),
            ),
            Text(
              "网页版自语确认登录",
              style: _style(22, AppColor.colorDefaultText),
            ),
            SizedBox(
              height: height(20),
            ),
            Text(
              "同步最近7天消息",
              style: _style(16, AppColor.colorGrey153),
            ),
            SizedBox(
              height: height(80),
            ),
            UniversalView().longBtn("确认登录", () {
              _qrLogin();
            }, widthSize: width(150)),
            TextButton(
              onPressed: () {
                Get.back();
              },
              child: Text(
                "取消登录",
                style: _style(16, AppColor.colorGrey153),
              ),
            ),
            SizedBox(
              height: height(90),
            ),
          ],
        ),
      ),
    );
  }
}
